#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>

int main()
{
    int fd = open("mem.txt", O_RDWR);
    if(-1 == fd) {
        perror("open error");
        exit(1);
    } 

    char* mem = mmap(NULL, 8, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
    if(MAP_FAILED == mem) {
        perror("mmap err");
        exit(1);
    }

    strcpy(mem, "HELLO");

    munmap(mem, 8);
    
    close(fd);
    return 0;
}

